<?php

namespace app\common\model;

class UserAgentRecord extends Base
{
    /**
     * 开启自动时间戳
     * @var bool
     */
    protected $autoWriteTimestamp = true;

    /**
     * 创建时间戳
     * @var string
     */
    protected $createTime = 'create_at';

    /**
     * 更新时间戳
     * @var string
     */
    protected $updateTime = 'update_at';

    /**
     * getMyAgentIdByOpenid
     * @param $appId
     * @param $openid
     * @return int
     */
    public function getMyAgentIdByOpenid($appId, $openid): int
    {
        $where = [['app_id', '=', $appId], ['openid', '=', $openid]];
        return $this->where($where)->order('create_at', 'asc',)->value('agent_id', 0);
    }
}